/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.spestimator.gui;

import com.compomics.spestimator.Spestimator;
import com.compomics.spestimator.gui.dialogs.NewSpeciesDialog;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author Kenneth
 */
public class SpestimatorGUI extends javax.swing.JFrame {

    private File fasta1;
    private File fasta2;
    private File param;
    private File mgf;
    private File output;
    private File searchGuiJar;
    private File peptideShakerJar;
    private String projectName;
    private static final Logger LOGGER = Logger.getLogger(SpestimatorGUI.class);
    private HashMap<String, String> speciesMap = new HashMap<>();

    /**
     * Creates new form SpestimatorGUI
     */
    public SpestimatorGUI() {
        initComponents();
        TableColumnModel cModel = speciesTable.getColumnModel();
        cModel.getColumn(0).setWidth(40);
        speciesTable.setColumnModel(cModel);
        speciesTable.repaint();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tfOutputFolder = new javax.swing.JTextField();
        tfProjectName = new javax.swing.JTextField();
        btnOutputFolder = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tfParam = new javax.swing.JTextField();
        tfSpectra = new javax.swing.JTextField();
        btnParam = new javax.swing.JButton();
        btnSpectra = new javax.swing.JButton();
        btnEstimate = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tfSgLocation = new javax.swing.JTextField();
        btnSgLocation = new javax.swing.JButton();
        tfPsLocation = new javax.swing.JTextField();
        btnPsLocation = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        speciesTable = new javax.swing.JTable();
        btnFasta6 = new javax.swing.JButton();
        btnFasta7 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Output"));

        jLabel5.setText("Outputfolder ");

        jLabel6.setText("Project name");

        tfOutputFolder.setText("C:\\Users\\Kenneth\\Documents\\Project_Material\\Spestimator_Example_Data\\Output");

        tfProjectName.setText("Human_Yeast");

        btnOutputFolder.setText("Add");
        btnOutputFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOutputFolderActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfProjectName, javax.swing.GroupLayout.PREFERRED_SIZE, 493, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfOutputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 493, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnOutputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {tfOutputFolder, tfProjectName});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tfOutputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnOutputFolder))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(tfProjectName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Input"));

        jLabel3.setText("SearchParameters");

        jLabel4.setText("Spectra");

        tfParam.setText("C:\\Users\\Kenneth\\Documents\\Project_Material\\Spestimator_Example_Data\\SearchGUI.parameters");

        tfSpectra.setText("C:\\Users\\Kenneth\\Documents\\Project_Material\\Spestimator_Example_Data\\qExactive01819.mgf");

        btnParam.setText("Add");
        btnParam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnParamActionPerformed(evt);
            }
        });

        btnSpectra.setText("Add");
        btnSpectra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSpectraActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tfSpectra)
                    .addComponent(tfParam, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnSpectra, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnParam, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfParam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnParam))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tfSpectra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnSpectra)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnEstimate.setText("ESTIMATE");
        btnEstimate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEstimateActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings"));

        jLabel8.setText("SearchGUI");

        jLabel9.setText("PeptideShaker");

        tfSgLocation.setText("C:\\Users\\Kenneth\\Documents\\Project_Material\\SearchGUI-1.14.4-windows\\SearchGUI-1.14.4\\SearchGUI-1.14.4.jar");
        tfSgLocation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfSgLocationActionPerformed(evt);
            }
        });

        btnSgLocation.setText("Add");
        btnSgLocation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSgLocationActionPerformed(evt);
            }
        });

        tfPsLocation.setText("C:\\Users\\Kenneth\\Documents\\NetBeansProjects\\peptide-shaker\\target\\PeptideShaker-0.23.0-beta\\PeptideShaker-0.23.0-beta.jar");
        tfPsLocation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfPsLocationActionPerformed(evt);
            }
        });

        btnPsLocation.setText("Add");
        btnPsLocation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPsLocationActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)
                        .addComponent(tfSgLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 493, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnSgLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(tfPsLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 493, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnPsLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 20, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel8, jLabel9});

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {tfPsLocation, tfSgLocation});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(tfSgLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnSgLocation, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(tfPsLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPsLocation))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Species"));

        speciesTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Taxonomy ID", "Fasta"
            }
        ));
        jScrollPane1.setViewportView(speciesTable);

        btnFasta6.setText("Add");
        btnFasta6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFasta6ActionPerformed(evt);
            }
        });

        btnFasta7.setText("Clear");
        btnFasta7.setMaximumSize(new java.awt.Dimension(51, 23));
        btnFasta7.setMinimumSize(new java.awt.Dimension(51, 23));
        btnFasta7.setPreferredSize(new java.awt.Dimension(51, 23));
        btnFasta7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFasta7ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 580, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnFasta7, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnFasta6, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 20, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(btnFasta6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnFasta7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 24, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(527, 527, 527)
                        .addComponent(btnEstimate, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnEstimate, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSgLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSgLocationActionPerformed
        getRequestedFile(searchGuiJar);
        tfSgLocation.setText(searchGuiJar.getAbsolutePath());
    }//GEN-LAST:event_btnSgLocationActionPerformed

    private void btnPsLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPsLocationActionPerformed
        getRequestedFile(peptideShakerJar);
        tfPsLocation.setText(peptideShakerJar.getAbsolutePath());
    }//GEN-LAST:event_btnPsLocationActionPerformed

    private void btnOutputFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOutputFolderActionPerformed
        getRequestedFile(output);
        tfOutputFolder.setText(output.getAbsolutePath());
    }//GEN-LAST:event_btnOutputFolderActionPerformed

    private void btnParamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnParamActionPerformed
        getRequestedFile(param);
        tfParam.setText(param.getAbsolutePath());
    }//GEN-LAST:event_btnParamActionPerformed

    private void btnSpectraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSpectraActionPerformed
        getRequestedFile(mgf);
        tfSpectra.setText(mgf.getAbsolutePath());
    }//GEN-LAST:event_btnSpectraActionPerformed

    private void btnEstimateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEstimateActionPerformed
        //Check if all files are not null
        boolean accepted = true;
        param = new File(tfParam.getText());
        mgf = new File(tfSpectra.getText());
        output = new File(tfOutputFolder.getText());
        searchGuiJar = new File(tfSgLocation.getText());
        peptideShakerJar = new File(tfPsLocation.getText());
        projectName = tfProjectName.getText();
        projectName = tfProjectName.getText();
        if (param == null | !param.exists()) {
            JOptionPane.showMessageDialog(this, "Please select a parameters file for the search");
            accepted = false;
        }
        if (mgf == null | !mgf.exists()) {
            JOptionPane.showMessageDialog(this, "Please select an spectrumfile for the search");
            accepted = false;
        }
        if (output == null | !output.exists()) {
            JOptionPane.showMessageDialog(this, "Please specify an outputfolder");
            accepted = false;
        }
        if (projectName == null || projectName.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Please specify a name for the project");
            accepted = false;
        }
        HashMap<String, String> speciesMap = getMapFromSpeciesTable();
        if (speciesMap.isEmpty() || speciesMap.size() < 2) {
            JOptionPane.showMessageDialog(this, "Please select at least two fasta species for the project");
            accepted = false;
        }
        if (accepted) {
            makeFastaString();
            makeTaxIDString();
            Spestimator.main(buildArgs());
        }
    }//GEN-LAST:event_btnEstimateActionPerformed

    private void btnFasta6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFasta6ActionPerformed
        new NewSpeciesDialog(this, true);
    }//GEN-LAST:event_btnFasta6ActionPerformed

    private void btnFasta7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFasta7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnFasta7ActionPerformed

    private void tfPsLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfPsLocationActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfPsLocationActionPerformed

    private void tfSgLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfSgLocationActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfSgLocationActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            LOGGER.error(ex);
        }
        //</editor-fold>
        Logger.getRootLogger().setLevel(Level.DEBUG);
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SpestimatorGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEstimate;
    private javax.swing.JButton btnFasta6;
    private javax.swing.JButton btnFasta7;
    private javax.swing.JButton btnOutputFolder;
    private javax.swing.JButton btnParam;
    private javax.swing.JButton btnPsLocation;
    private javax.swing.JButton btnSgLocation;
    private javax.swing.JButton btnSpectra;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable speciesTable;
    private javax.swing.JTextField tfOutputFolder;
    private javax.swing.JTextField tfParam;
    private javax.swing.JTextField tfProjectName;
    private javax.swing.JTextField tfPsLocation;
    private javax.swing.JTextField tfSgLocation;
    private javax.swing.JTextField tfSpectra;
    // End of variables declaration//GEN-END:variables

    private void getRequestedFile(File targetFile) {
        JFileChooser chooser = new JFileChooser();
        chooser.setMultiSelectionEnabled(false);
        int option = chooser.showOpenDialog(SpestimatorGUI.this);
        if (option == JFileChooser.APPROVE_OPTION) {
            targetFile = chooser.getSelectedFile();
            LOGGER.info("Selected " + targetFile);
        }

    }

    private String[] buildArgs() {
        /*       options.addOption("fasta_file_1", true, "user specified fasta for species 1");
         options.addOption("fasta_file_2", true, "user specified fasta for species 2");
         options.addOption("param_file", true, "user specified searchparameters file (created by searchgui)");
         options.addOption("mgf_file", true, "user specified spectrum file");
         options.addOption("projectID", true, "the requested projectID");
         options.addOption("output_folder", true, "the directory all files should finally be stored");
         options.addOption("searchgui_path", true, "the filepath to the searchgui jar");
         options.addOption("peptideshaker_path", true, "the filepath to the peptideshaker jar");*/
        ArrayList<String> arguments = new ArrayList<>();
        arguments.add("-fasta_files");
        arguments.add(makeFastaString());
        arguments.add("-taxonomy_IDs");
        arguments.add(makeTaxIDString());
        arguments.add("-param_file");
        arguments.add(param.getAbsolutePath());
        arguments.add("-mgf_file");
        arguments.add(mgf.getAbsolutePath());
        arguments.add("-output_folder");
        arguments.add(output.getAbsolutePath());
        arguments.add("-projectID");
        arguments.add(projectName);
        arguments.add("-peptideshaker_path");
        arguments.add(peptideShakerJar.getAbsolutePath());
        arguments.add("-searchgui_path");
        arguments.add(searchGuiJar.getAbsolutePath());
        String[] argumentsAsArray = new String[arguments.size()];
        return arguments.toArray(argumentsAsArray);
    }

    private HashMap<String, String> getMapFromSpeciesTable() {
        TableModel model = speciesTable.getModel();
        speciesMap.clear();
        for (int count = 0; count < model.getRowCount(); count++) {
            speciesMap.put(model.getValueAt(count, 0).toString(), model.getValueAt(count, 1).toString());
        }
        return speciesMap;
    }

    private String makeTaxIDString() {
        StringBuilder builder = new StringBuilder();
        for (String aTaxId : speciesMap.values()) {
            builder.append(aTaxId).append(",");
        }
        return builder.substring(0, builder.length() - 1);
    }

    private String makeFastaString() {
        StringBuilder builder = new StringBuilder();
        for (String aTaxId : speciesMap.keySet()) {
            builder.append(aTaxId).append(",");
        }
        return builder.substring(0, builder.length() - 1);
    }

    public void addNewSpecies(String taxID, String fasta) {
        DefaultTableModel myModel = (DefaultTableModel) speciesTable.getModel();
        myModel.addRow(new Object[]{taxID, fasta});
        speciesTable.setModel(myModel);
        speciesTable.revalidate();
    }
}
